package com.lbs.dao.Impl;

import com.lbs.dao.StuDao;
import com.lbs.entity.Stu;
import com.lbs.until.BaseDaoUntil;

import java.util.List;

/**
 * @author Administrator
 * @date 2021/5/18 13:58
 * @description
 **/
public class StuDaoImpl extends BaseDaoUntil<Stu> implements StuDao {
    @Override
    public int addStu(Stu stu) {
        String sql = "insert into stu(name,gender,bir,hobby,photo) values(?,?,?,?,?)";
        Object[] param = {stu.getName(), stu.getGender(), stu.getBir(), stu.getHobby(), stu.getPhoto()};
        return update(sql, param);
    }

    @Override
    public List<Stu> findStuByNameAndGender(String sql, Object... param) {
        return findMore(sql, Stu.class, param);
    }

    @Override
    public int delStuById(String ids) {
        String sql = "delete from stu where id in(" + ids + ")";
        return update(sql, null);
    }

    @Override
    public int updateStuById(Stu stu) {
        String sql = "update stu set name = ?,gender = ?,bir= ?,hobby = ?,photo = ? where id = ?";
        Object[] param = {stu.getName(),stu.getGender(),stu.getBir(),stu.getHobby(),stu.getPhoto(),stu.getId()};
        return update(sql,param);
    }

    @Override
    public Stu selectStuById(String id) {
        String sql = "select * from stu where id = ?";
        return findOne(sql,Stu.class,id);
    }

}
